//
//  CustomUIScrollView.m
//  UI06_UIScrollView
//
//  Created by aaaaaa on 16/6/13.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CustomUIScrollView.h"



@implementation CustomUIScrollView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/




- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setProperty];
    }
    
    return self;
}

- (void)setProperty{
    /*
     * 重点
     * frame设置的是scrollView的可视范围， contentSize设置的是scrollView的滚动范围
     * 当contentSize的width大于frame的width时，水平方向可以滚动，小于等于时水平方向不可以滚动
     * 当contentSize的height大于frame的height时，竖直方向可以滚动，小于等于时竖直方向不可以滚动
     */
    //self.contentSize = CGSizeMake(self.frame.size.width * self.count, self.frame.size.height);
    
    /** 不显示滑动条**/
    self.showsVerticalScrollIndicator = NO; /**垂直方向**/
    self.showsHorizontalScrollIndicator = NO; /**水平方向**/
    
    //设置分页效果
    self.pagingEnabled = YES;
    
    //回弹效果 默认开启
    self.bounces = NO;
    
    //设置放大和缩小的比例因子
//    self.maximumZoomScale = 2;
//    self.minimumZoomScale = 0.5;
}

/*添加图片*/
- (void)addPictures:(NSArray<UIImage *> *)pictureArray {
    
    self.contentSize = CGSizeMake(self.frame.size.width * pictureArray.count, self.frame.size.height);
    
    //创建子视图
    for (int i = 0; i < pictureArray.count; i++) {
        
        /*创建小的scrollView**/
        UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(self.frame.size.width * i, 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds))];
        scroll.delegate = self;
        scroll.maximumZoomScale = 2.0;
        scroll.minimumZoomScale = 0.5;
        
        UIImageView *imageView  = [[UIImageView alloc] initWithImage:pictureArray[i]];
        imageView.frame = CGRectMake(0, 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds));
        //CGRectGetWidth(self.bounds) 获取参数的宽度
        
        [scroll addSubview:imageView];
        [self addSubview:scroll];
        [scroll release];
        [imageView release];
    }
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    return scrollView.subviews.firstObject;
}





@end
